home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
preccx
/
prccx240.lha
/
common.c
< prev
next >
Wrap
Text File
|
1993-04-18
|
5KB
|
284 lines
/*
parser suite - and / or / nothing / something parsers
parser = [token] -> ([token],status)
implemented as sideeffecting on [token], returns status.
*/
# include <stdarg.h>
# include "cc.h"
STATUS p_andparse (p, q, o)
PARSER p, q;
ACTION *o;
{
status tok;
tok = p_andparse0 (p, q);
if (GOODSTATUS(tok))
pushACTION(o);
return (tok);
}
STATUS p_nothing0 ()
/*
p_parser succeeds without looking at any tokens from
the input stream.
*/
{
pushINCR;
return (SUCCESS);
}
STATUS p_nothing (k)
ACTION *k;
{
PARSER p_nothing0;
return (p_attach(p_nothing0,k));
}
STATUS p_anything0 ()
/*
Parser which takes any token at all - except 0 - and places it as
a constant on the program stack. This p_parser only fails at EOS.
*/
{
TOKEN c;
VALUE v;
c = *pstr;
v = lvbuff[pstr-buffer];
if (c)
{
MOVEON;
pushVALUE(v);
return (OK(v)); /* so CAN'T use attribute 0 */
}
return (FAILURE);
}
STATUS p_anything (k)
ACTION *k;
{
PARSER p_anything;
return (p_attach (p_anything0,k));
}
STATUS p_first0 ()
/*
This p_parser only succeeds at BOS and does nothing
*/
{ /* pstr CAN'T be < buffer. I am just being careful */
if ((void*)pstr <= (void*)buffer || pstr[-1]==(TOKEN)0) {
pushVALUE(SUCCESS);
return (SUCCESS);
}
/* doesnt move on */
return (FAILURE);
}
STATUS p_first (k)
ACTION *k;
{
PARSER p_first0;
return(p_attach(p_first0,k));
}
STATUS p_eof0 ()
{
if (yytchar==EOF) {
pushVALUE(SUCCESS);
return (SUCCESS);
}
return (FAILURE);
}
STATUS p_uerror0 (p)
PARSER *p;
{
pushEXIT;
pc=0;
pc=p_evaluate ();
pc=0; /* we have to write the next program in the right place */
if (yytchar!=EOF && 0==*pstr && /* then we can ask */
mygets(buffer,lvbuff)==0)
pstr=maxp=buffer;
passcount++;
p_enargs= 0;
p_entry = p; /* set the btck_error reentry pt */
fptr = fstack+1; /* reset the frame pointer - we won't backtrack */
return (SUCCESS);
/* and don't reset STACKVALUE *value because we may later backtrack
to earlier stack values */
}
STATUS p_uniq0 ()
{
return p_uerror0(0);
}
STATUS p_lastuniq0 ()
{
if (yytchar==EOF) /* we saw EOF already so don't try again */
return FAILURE;
if (0 == *pstr) /* we're in the right place to try & move on */
{
pushEXIT; /* remember to execute before pulling ...*/
pc=0;
pc=p_evaluate ();
pc=0; /* ... a new line */
if (mygets(buffer,lvbuff)==0 && yytchar!=EOF)
{ /* we got a new line */
pstr=maxp=buffer;
pushVALUE(p_lastuniq0);
passcount++;
fptr = fstack+1; /* reset the frame pointer -
* we won't backtrack */
return (SUCCESS);
}
/* at EOF */
return (SUCCESS);
}
/* not at EOL */
return(FAILURE);
}
STATUS p_last0 ()
/*
This p_parser only succeeds at EOS.
*/
{
if ((yytchar!=EOF) && (0 == *pstr)) /* does move on */
{
MOVEON;
pushVALUE(EOF);
/* if ((mygets(pstr,lvbuff+(pstr-buffer))==0)&&(yytchar!=EOF)) {
return (OK(EOF));
}
*/ /* the MOVEON did the pull */
return (OK(EOF));
}
return (FAILURE);
}
STATUS p_last (k)
ACTION *k;
{
PARSER p_last0;
return (p_attach (p_last0, k));
}
STATUS p_exactly0 (c)
/*
this p_parser only succeds when given token c.
It does NOT place the token as a literal on the program stack.
*/
TOKEN c;
{
VALUE v;
if (*pstr && *pstr == c)
{ /* read the attribute value */
v=lvbuff[pstr-buffer];
MOVEON;
pushVALUE(v); /* save the attribute */
return (OK(v));
}
return (FAILURE);
}
STATUS p_notexactly0 (c)
/*
this p_parser only succeds when given a TOKEN not equal to c.
It places the token as a literal on the program stack.
*/
TOKEN c;
{
VALUE v;
if (*pstr && *pstr != c)
{
c=*pstr;
v=lvbuff[pstr-buffer];
MOVEON;
pushVALUE(v);
return (OK(v));
}
return (FAILURE);
}
STATUS p_exactly (c,k)
TOKEN c;
ACTION *k;
{
PARSER p_exactly0;
status tok;
tok = p_exactly0 (c);
if (GOODSTATUS(tok))
pushACTION(k);
return (tok);
}
STATUS p_attach0 (p)
PARSER p;
{
return(p ());
}
STATUS p_range (p,f)
PREDICATE *p;
ACTION *f;
{
status tok;
tok = p_range0 (p);
if (GOODSTATUS(tok))
pushACTION(f);
return (tok);
}
VOID p_nop()
/*
a very trivial stack manipulation action
*/
{
}